package org.cytoscape.myapp.cytoscape_app_v1.internal.visual;

import java.awt.Color;
import java.awt.Paint;
import java.util.HashMap;
import java.util.List;

import org.cytoscape.myapp.cytoscape_app_v1.internal.helpers.ModelUtils;
import org.cytoscape.view.model.VisualProperty;
import org.cytoscape.view.vizmap.VisualMappingFunction;
import org.cytoscape.view.vizmap.mappings.BoundaryRangeValues;
import org.cytoscape.view.vizmap.mappings.ContinuousMapping;

public class MappingFunctionConcreteContinuousColor implements MappingFunctionFactory{

	@Override
	public <T> VisualMappingFunction createVisualMappingFunction(
			String attribute, Class<? extends T> type,
			VisualProperty<T> property,
			HashMap<String, Object> propertyAttributes,
			VisualInstanceDependecies dependecies) {
		ContinuousMapping mapping = (ContinuousMapping)
				dependecies.getVmfFactoryC().createVisualMappingFunction(attribute, type, property);
		
		List<Double> sortValues = ModelUtils.getColumnValueSorted(dependecies.getApplicationManager().getCurrentNetwork(), attribute);
		
		Double val1 = sortValues.get(2);
		Double val2 = sortValues.get(sortValues.size()-2);

		Color color1 = (Color)propertyAttributes.get("ColorOne");
		Color color2 = (Color)propertyAttributes.get("ColorTwo");
		
		
		BoundaryRangeValues<Paint> brv1 = new BoundaryRangeValues<Paint>(Color.blue, Color.CYAN, Color.yellow);
		BoundaryRangeValues<Paint> brv2 = new BoundaryRangeValues<Paint>(Color.yellow, Color.orange, Color.RED);
		
		mapping.addPoint(val1, brv1);
		mapping.addPoint(val2, brv2);
		
		return mapping;
	}

	public VisualMappingFunction createVisualMappingFunction(String attribute,
			Class<Double> type,
			VisualProperty<Paint> property,
			Object propertyAttributes, VisualInstanceDependecies dependecies) {
		ContinuousMapping mapping = (ContinuousMapping)
				dependecies.getVmfFactoryC().createVisualMappingFunction(attribute, type, property);
		
		List<Double> sortValues = ModelUtils.getColumnValueSortedEdge(dependecies.getApplicationManager().getCurrentNetwork(), attribute);
		
		Double val1 = sortValues.get(2);
		Double val2 = sortValues.get(sortValues.size()-2);

		Color color1 = (Color)((HashMap<String,Object>) propertyAttributes).get("ColorOne");
		Color color2 = (Color)((HashMap<String, Object>) propertyAttributes).get("ColorTwo");
		
		
		BoundaryRangeValues<Paint> brv1 = new BoundaryRangeValues<Paint>(Color.WHITE, Color.YELLOW, color1);
		BoundaryRangeValues<Paint> brv2 = new BoundaryRangeValues<Paint>(color2, Color.GRAY, Color.BLACK);
		
		mapping.addPoint(val1, brv1);
		mapping.addPoint(val2, brv2);
		
		return mapping;
		
		
	}

//	@Override
//	public <T> VisualMappingFunction createVisualMappingFunction(
//			String attribute, Class<? extends T> type,
//			VisualProperty<T> property,
//			HashMap<String, Object> propertyAttributes,
//			VisualInstanceDependecies dependecies) {
//		
//		ContinuousMapping mapping = (ContinuousMapping)
//				dependecies.getVmfFactoryC().createVisualMappingFunction(attribute, type, property);
//		
//		List<Double> sortValues = ModelUtils.getColumnValueSorted(dependecies.getApplicationManager().getCurrentNetwork(), attribute);
//		
//		Double val1 = sortValues.get(2);
//		Double val2 = sortValues.get(sortValues.size()-2);
//
//		Color color1 = (Color)propertyAttributes.get("ColorOne");
//		Color color2 = (Color)propertyAttributes.get("ColorTwo");
//		
//		
//		BoundaryRangeValues<Paint> brv1 = new BoundaryRangeValues<Paint>(Color.WHITE, Color.YELLOW, color1);
//		BoundaryRangeValues<Paint> brv2 = new BoundaryRangeValues<Paint>(color2, Color.GRAY, Color.BLACK);
//		
//		mapping.addPoint(val1, brv1);
//		mapping.addPoint(val2, brv2);
//		
//		return mapping;
//	}

}
